<template>
  <div>

    <el-table
      :data="tableData"
      syle="width: 100%"
      :header-cell-style="{ textAlign: 'center' }"
      :default-sort="{ prop: 'typeId', order: 'null' }"
      highlight-current-row
      fit
      @row-click="showMark"
    >

      <el-table-column prop="typeId" label="编号" align="center" sortable />

      <el-table-column prop="typeName" label="类型名称" align="center" />
      <!-- <el-table-column
          prop="password"
          label="密码"
          width="120">
        </el-table-column> -->

    </el-table>
    <pagination
      :total="total"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
      @pagination="getList"
      layout="sizes, prev, next, jumper"
    />

  </div>

</template>

<script>
import Pagination from '@/components/Pagination'

export default {
  name: 'MachineList',
  components: { Pagination },
  props: {
    tableData: Array, // 使用 props 声明接收父组件传递的 tableData
    message: String,
    total: Number
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10
      },
      typeNames: [],
      typeId: ''
    }
  },
  created() {
    var myuser = this.$store.getters.getUser
    this.isAdmin = myuser.isAdmin
  },
  mounted() {
  },
  methods: {
    getList() {
      // console.log(this.tableData[0].typeId + this.listQuery.limit)
      // if (this.tableData[0].typeId + this.listQuery.limit > this.total) { 
      //   this.listQuery.page--
      //   return
      // }
      const tem = this.listQuery
      this.$emit('getList', tem)
    },
    toUpdateUser(typeId) {
      this.$router.push('/machine_type/machine_type-update/' + typeId)
    },
    deleteUser(typeId) {
      const obj = this
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios({
          method: 'delete',
          url: 'http://localhost:8081/type/removeMachineType/' + typeId
        }).then(function(respones) {
          const ret = respones.data
          if (ret.code == 1) {
            obj.$message({
              type: 'success',
              message: '删除成功!'
            })
            obj.getList()
          } else {
            obj.$message.error('该类型存在关联项目,不能删除！')
          }
        })
      }).catch(() => {
        obj.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    saveState() {
      // 模块化后，调用 state 的代码修改为 this.$store.state.myuser
      sessionStorage.setItem('userState', JSON.stringify(this.$store.state.myuser))
    },
    showMark(row, event, column) {
      console.log('测试点击')

      this.$emit('handleFather', row)
    }
  }

}
</script>
